import java.util.*;
public class Test {
    private int year;
    private int month;
    private int day;

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }



    public static void transform(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }
    public static void setArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i+1;
        }
    }
    public static int[] findNum(int[] arr,int sum){
        //假设每种输入只会对应一个答案
        int[] answer = new int[2];
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j < arr.length; j++) {
                int Sum = 0;
                Sum = arr[i]+arr[j];
                if (sum==Sum){
                    answer[0] = i;
                    answer[1] = j;
                    return answer;
                }
            }
        }
        return answer;
    }
    //实现冒泡排序(升序排序)
    public static void maopaoSort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            int flag = 0;
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = tmp;
                    flag = 1;
                }
            }
            if(flag == 0){
                return;
            }
        }
        System.out.println(arr);
    }
    //判断一个数组是否有序
    public static void isSort(int[] arr){
        boolean flag = false;
        for (int i = 0; i < arr.length-1; i++) {
            if(arr[i]>arr[i+1]){
                flag = true;
            }
        }
        if(flag==true){
            System.out.println("不是升序");
        }else {
            System.out.println("是升序");
        }
    }
    //二分查
    public static void binarySearch(int[]arr,int key){
        int left = 0;
        int right = arr.length-1;
        while (arr[right]>arr[left]){
            int mid = (left+right)/2;
            if (arr[mid]==key){
                System.out.println("找到了！");
                return;
            }
            if(arr[mid]>key){
                right = mid-1;
            }else {
                left = mid+1;
            }
        }
        System.out.println("没找到！");
    }

    //int[] src = {1,3,5,7,9,11,13,15,17};
    //copyOf(是复制src数组从0开始的两个元素到新的数组对象)
    //int[] copyof=Arrays.copyOf(src, 2);
    //结果为：[1, 3]
    //得到一个新的数组.
    public static int[] myCopyof(int[] arr,int n){
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = arr[i];
        }
        return ret;
    }
    public static String mytoString(int[] arr){
        String ret = new String();
        ret += "[";
        for (int i = 0; i < arr.length; i++) {
            if(i == arr.length-1){
                ret += arr[arr.length-1]+"]";
                break;
            }
            ret += arr[i]+", ";
        }
        return ret;
    }
    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6};
        transform(array);
        int[] array1 = new int[100];
        setArray(array1);
//        System.out.println(Arrays.toString(array1));
//        int[] array2 = new int[]{2,7,11,15};
//        System.out.println(Arrays.toString(findNum(array2,9)));
        //int[] array2 = new int[]{3,2,20,1,4};
        //maopaoSort(array2);
        //System.out.println(Arrays.toString(array2));
        //int[] array3 = new int[]{1,5,3,4};
//        isSort(array3);
        //binarySearch(array3,55);
        int[] array4 = new int[]{1,2,3,4,5,6};
        System.out.println(Arrays.toString(myCopyof(array4,5)));
        System.out.println(mytoString(array4));
    }
}
